import 'package:flutter/material.dart';

class HitTestBehaviorExps extends StatelessWidget {
  const HitTestBehaviorExps({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Center(
          child: Column(
            children: [
              GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  print('整个组件响应点击事件');
                },
                child: Container(
                  width: 300,
                  height: 100,
                  color: Colors.blue.withOpacity(0.3), // 半透明背景
                  child: const Center(
                    child: Text(
                      '点击我（整个区域都算）',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ),
              const SizedBox(
                height: 20,
              ),

              GestureDetector(
                onTap: () {
                  print('当前组件和子组件均响应');
                },
                behavior: HitTestBehavior.translucent,
                child: Container(
                  width: 400,
                  height: 100,
                  color: Colors.red.withOpacity(0.3),
                  child: Center(
                    child: ElevatedButton(
                      onPressed: () {
                        print('处理点击事件');
                      },
                      child: const Text('点击我'),
                    ),
                  ),
                ),
              ),
              const SizedBox(
                height: 20,
              ),

            ],
          ),
        ),
      ),
    );
  }
}
